import { EventBus } from '@/store/index'

export const rotate = {
  data(){
    return{
      isPlayRotate3d: false
    }
  },
  created(){
    if(this.item.events.rotate3d) {
      EventBus.$off("rotate3d", this.onRotate3d)
      EventBus.$on("rotate3d", this.onRotate3d)
    }
  },
  computed: {
    getRotateClass(){
      let classes = [{
        'isPlay': this.isPlayRotate3d,
        'wid-hei-inherit': true,
        'transform-center': true
      }];
      return classes;
    },
    getRotateConClass() {
      let classes = [{
        'rotate3d': this.isRotate3d,
        'wid-hei-inherit': true,
      }];
      return classes;
    },
    isRotate3d() {
      return this.item && this.item.events.rotate3d ? true : false
    },
  },
  methods: {
    onRotate3d({isPlay, id}){
      if(id){
        if(this.item.id == id){
          this.isPlayRotate3d = isPlay
        }
      }else{
        if(this.item.rotateSetTimeoutCb){
          window.clearTimeout(this.item.rotateSetTimeoutCb);
        }
        this.isPlayRotate3d = isPlay
      }
    },
  },
  beforeUnmount() {
    if(this.item.events.rotate3d){
      EventBus.$off("rotate3d", this.onRotate3d);

      if(this.item.rotateSetTimeoutCb){
        window.clearTimeout(this.item.rotateSetTimeoutCb);
      }
    }
  }
}
